<template>
  <a-modal
    title="物资招标定标选择"
    :visible="visible"
    class="pub-middle-dialog"
    @ok="handleOk"
    @cancel="visible=false"
  >
    <searchData :search-data="searchArr" @search="search" />
    <b-table
      ref="table"
      :columns="columns"
      :request="loadData"
      :selectConfig="{use: true, type: 'radio',rowKey: 'id' }"
      @row-click="rowClick"
    >
      <span slot="index" slot-scope="text, record, index">{{ index + 1 }}</span>
      <template slot="auditStatusStr" slot-scope="text, record, index">
        <list-status :status="record.auditStatus" :text="text" />
      </template>
    </b-table>

  </a-modal>
</template>
<script>
import { findListByMain } from '@/api/material/procurement/tender'

export default {
  name: 'a' + Date.now(),
  data: function() {
    return {
      queryParam: {},
      visible: false,
      columns: [
        {
          title: '序号',
          scopedSlots: { customRender: 'index' },
          width: 70
        },
        {
          title: '物资招标定标编号',
          dataIndex: 'selectionCode'
        },
        {
          title: '工程名称',
          dataIndex: 'wbsName'
        },
        {
          title: '招标名称',
          dataIndex: 'materialPurchaseApplyName'
        }
      ],
      searchArr: [
        {
          name: '物资招标定标编号',
          value: 'selectionCode',
          type: 'input'
        }
      ],
      loadData: q => {
        let p = Object.assign({
          auditStatus: 'PAST',
          isCollect: this.$userType() !== 'PD' ? 'Y' : 'N',
          quote: 1
        }, q, this.queryParam)
        return findListByMain({}, p)
      },
      selectedRowKeys: [],
      selectRow: null
    }
  },
  methods: {
    open: function() {
      this.visible = true
      this.search()
      // this.selectRow = null
    },
    handleOk: function() {
      if (!this.selectRow) {
        this.$message.error('请选择基础数据')
        return
      }
      this.visible = false
      this.$emit('getSign', this.selectRow)
    },
    search(val) {
      this.pageNo = 1
      this.queryParam = val
      this.$refs.table && this.$refs.table.getData(null, true)
    },
    rowClick(e, row) {
      this.selectRow = row
    }
  }
}
</script>
